/* eslint-disable */
<template>
	<div class="dataBandResource">
		<div class="userCollapse" >
			<el-form class='searchform' :inline="true" :model="form" ref="form" label-width="110px">
				<el-row>
					<el-col :span="24" class="flex flex-vc rowItem">
						<el-button  @click="showcollse=!showcollse" class="showsearchBtn" type="info"
							 :icon="showcollse?'el-icon-caret-top':'el-icon-caret-bottom'"  size="mini" >{{showcollse?$t('common.collseHide'):$t('common.spread')}}</el-button>
						<span class="searchTitle flex-vc inline_flex flex-hc">{{$t('searchEaraLabel.accountAndEmp')}}</span>
						<div class="userCollapse_item" v-if="showcollse">
							<el-form-item :label="$t('common.username')+'：'">
			  					<el-input v-model="form.username" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
							<el-form-item :label="$t('common.accountStatus')+'：'">
								<el-select v-model="form.accountStatus" :placeholder="$t('common.selectPlaceholder')"  clearable>
									<el-option v-for="(item,index) in statusDic" :key="index" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item :label="$t('common.empCode')+'：'">
								<el-input v-model="form.empCode" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
							<el-form-item  :label="$t('common.empName1')+'：'">
								<el-input v-model="form.empName" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
							<el-form-item :label="$t('common.empStatus')+'：'">
								<el-select v-model="form.empStatus" :placeholder="$t('common.selectPlaceholder')"  clearable>
									<el-option v-for="(item,index) in empstatusDic" :key="index" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
								<el-form-item :label="$t('common.positionName')+'：'">
								<el-input v-model="form.positionName" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
							<el-form-item :label="$t('common.orgName')+'：'">
								<el-input v-model="form.orgName" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
							<el-form-item :label="$t('common.netCode')+'：'">
								<el-input v-model="form.netCode" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
						</div>
						<div class="userCollapse_hide" v-if="!showcollse">
							<span>{{$t('common.username')}}:</span><strong>【{{form.username?form.username:$t('common.all')}}】</strong>
							<span>{{$t('common.accountStatus')}}:</span><strong>【{{getSearchAreaName('accountStatus')}}】</strong>
							<span>{{$t('common.empCode')}}:</span><strong>【{{form.empCode?form.empCode:$t('common.all')}}】</strong>
							<span>{{$t('common.empName1')}}:</span><strong>【{{form.empName?form.empName:$t('common.all')}}】</strong>
							<span>{{$t('common.empStatus')}}:</span><strong>【{{getSearchAreaName('empStatus')}}】</strong>
							<span>{{$t('common.positionName')}}:</span><strong>【{{form.positionName?form.positionName:$t('common.all')}}】</strong>
							<span>{{$t('common.orgName')}}:</span><strong>【{{form.orgName?form.orgName:$t('common.all')}}】</strong>
							<span>{{$t('common.netCode')}}:</span><strong>【{{form.netCode?form.netCode:$t('common.all')}}】</strong>
						</div>
					</el-col>
					<el-col :span="24" class="flex flex-vc rowItem">
						<span class="searchTitle flex-vc inline_flex flex-hc">{{$t('searchEaraLabel.dataGroup')}}</span>
						<div class="userCollapse_item" v-if="showcollse">
							<el-form-item :label="$t('common.resourceName')+'：'">
								<el-select v-model="form.resourceName" filterable :placeholder="$t('common.selectPlaceholder')"	:filter-method="resourceOptionsFun" clearable>
									<el-option
									  v-for="item in resourceOptions"
									  :key="item.code"
									  :label="item.label"
									  :value="item.code">
									</el-option>
								</el-select>
							</el-form-item>
							<el-form-item :label="$t('common.dataGroupName')+'：'">
								<el-input v-model="form.dataGroupName" :placeholder="$t('common.inputPlaceholder')"></el-input>
							</el-form-item>
							<el-form-item :label="$t('common.dataGroupStatus')+'：'">
								<el-select v-model="form.dataGroupStatus" :placeholder="$t('common.selectPlaceholder')"   clearable>
									<el-option v-for="(item,index) in statusDic" :key="index" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</div>
						<div class="userCollapse_hide" v-if="!showcollse">
							<span>{{$t('common.resourceName')}}:</span><strong>【{{getSearchAreaName('resourceName')}}】</strong>
							<span>{{$t('common.dataGroupName')}}:</span><strong>【{{form.dataGroupName?form.dataGroupName:$t('common.all')}}】</strong>
							<span>{{$t('common.dataGroupStatus')}}:</span><strong>【{{getSearchAreaName('dataGroupStatus')}}】</strong>
						</div>
					</el-col>
					<el-col :span="24" class="flex flex-vc rowItem">
						<span class="searchTitle flex-vc inline_flex flex-hc">{{$t('searchEaraLabel.assign')}}</span>
						<div class="userCollapse_item" v-if="showcollse">
							<el-form-item :label="$t('common.ruleType')+'：'">
								<el-select v-model="form.ruleType" :placeholder="$t('common.selectPlaceholder')"  clearable>
									<el-option v-for="(item,index) in typeDic" :key="index" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item :label="$t('common.startTm')+'：'">
								<el-date-picker v-model="form.startTm"  type="date" value-format="yyyy-MM-dd" :placeholder="$t('common.selectDate')"> </el-date-picker>
							</el-form-item>
							<el-form-item :label="$t('common.endTm')+'：'">
								<el-date-picker v-model="form.endTm"  type="date" value-format="yyyy-MM-dd"  :placeholder="$t('common.selectDate')"> </el-date-picker>
							</el-form-item>
							<el-form-item :label="$t('common.accreditStatus')+'：'">
								<el-select v-model="form.accreditStatus" :placeholder="$t('common.selectPlaceholder')"  >
									<el-option v-for="(item,index) in statusDic" :key="index" :label="item.label" :value="item.value"></el-option>
								</el-select>
							</el-form-item>
						</div>
						<div class="userCollapse_hide" v-if="!showcollse">
							<span>{{$t('common.ruleType')}}:</span><strong>【{{getSearchAreaName('ruleType')}}】</strong>
							<span>{{$t('common.startTm')}}:</span><strong>【{{form.startTm?form.startTm:$t('common.all')}}】</strong>
							<span>{{$t('common.endTm')}}:</span><strong>【{{form.endTm?form.endTm:$t('common.all')}}】</strong>
							<span>{{$t('common.accreditStatus')}}:</span><strong>【{{getSearchAreaName('accreditStatus')}}】</strong>
						</div>
					</el-col>
				</el-row>
			</el-form>

		</div>
		<!--操作区域-->
		<el-row>
			<el-col :span="18">
				<div class="operateBtn" >
					<el-button  @click="handleDataAssignVisible=true" >{{$t('modules.accountDataGroupManage.add')}}</el-button>
					<el-button  @click="handleResourceBatchVisible=true" >{{$t('modules.accountDataGroupManage.batchAdd')}}</el-button>
					<el-button  @click="beforeupdate(1)" >{{$t('modules.accountDataGroupManage.modify')}}</el-button>
					<el-button v-if="form.accreditStatus!=0"  @click="batchDisabled">{{$t('modules.accountDataGroupManage.disabled')}}</el-button>
				</div>
			</el-col>
			<el-col :span="6">
				<div class="searchBtn">
					<el-button type="primary" @click="onSearch" >{{$t('common.searchBtn')}}</el-button>
					<el-button  type="primary" @click="resetSearch" >{{$t('common.resetBtn')}}</el-button>
				</div>
			</el-col>
		</el-row>

		<!--数据组列表-->
		<el-table class="data-list "  v-loading="loadind" ref="multipleTable" :data="dataList" border @selection-change="selectChange"  highlight-current-row  >
			<el-table-column :selectable="selectableFun" type="selection" width="55" ></el-table-column>
			<el-table-column v-for="item in tableVisibleArr" :key="item.prop" :prop="item.prop" :label="item.label"  align="center"  show-overflow-tooltip :formatter="formatter"></el-table-column>
		</el-table>
		<div class="tablebottom" style="position:relative;">
			<el-pagination
			  @size-change="pageSizeChange"
			  @current-change="handleCurrentChangePage"
			  :current-page="pagination.pageNum"
			  :page-sizes="[10,20, 50, 100, 200]"
			  :page-size="pagination.pageSize"
			  layout="->,prev, pager, next, jumper, sizes,total"
			  :total="pagination.totalSize">
			</el-pagination>
			<!-- 自定义表格字段组件 -->
			<defined-table storageName="basp_accountDataGroupManage" :headArr="headArr" :selectArr="tableVisibleArr" @saveAutoDefinedTable="saveAutoDefinedTable"></defined-table>
		</div>
		<!--启用禁用时填写对应的生效失效时间-->
		<validity-date   path="limitToday"  :visible="statusChange" @validityDateClose="validityDateClose1"  @submitDateForm="stateChangeConfirm"></validity-date>
		<!--修改已勾选的百源账号数据对应的生效失效时间-->
		<validity-date  :earliestTime="new Date().getTime()"  :start="dataSourceRow.startTm"  :end="dataSourceRow.endTm" :visible="newlyFormVisible" @validityDateClose="validityDateClose"  @submitDateForm="submitDateForm"></validity-date>
		<!--数据操作弹框-->
		<handle-resource :visible="handleDataAssignVisible"  @exit="giveupFun('handleDataAssignVisible')"   @close="handleDataAssignVisible=false;" @dataHandleSave="dataHandleSave"></handle-resource>
		<!--新增数据组批量授权操作弹框-->
		<handle-resource-batch :visible="handleResourceBatchVisible"  @exit="giveupFun('handleResourceBatchVisible')"   @close="handleResourceBatchVisible=false;" @dataHandleBatchSave="dataHandleBatchSave"></handle-resource-batch>

	</div>
</template>
<script>
import {
    Message, Notification, MessageBox, Loading
} from 'element-ui'
import validityDate from "../components/validityDate"
import definedTable from "../components/definedTable"
import handleResource from "../components/handleResource"
import handleResourceBatch from "../components/handleResourceBatch"
export default {
	name: 'accountDataGroupManage',
    components: {
        validityDate,
        definedTable,
        handleResource,
        handleResourceBatch
    },
    data () {
        return {
            statusChange: false,
            showcollse: false,
            form: {
                username: '',
                accountStatus: '',
                empCode: '',
                empName: '',
                empStatus: '',
                positionName: '',
                orgName: '',
                netCode: '',
                resourceName: '',
                dataGroupName: '',
                dataGroupStatus: '',
                ruleType: '',
                isCustom: "",
                accreditStatus: 1,
                startTm: '',
                endTm: ''
            },
            dataSourceRow: {
                username: '',
                sysUserName: '',
                empName: '',
                positionName: '',
                orgName: '',
                systemName: '',
                roleName: '',
                resourceName: '',
                dataGroupName: ''
            },
            typeDic: [
			   { value: "A", label: (window.sessionStorage.getItem('lang') == 'zh-CN') ? "A类" : 'type A' },
			   { value: "B", label: (window.sessionStorage.getItem('lang') == 'zh-CN') ? "B类" : 'type A' },
			   { value: "C", label: (window.sessionStorage.getItem('lang') == 'zh-CN') ? "C类" : 'type C' }],
            statusDic: [
                { value: 1, label: (window.sessionStorage.getItem('lang') == 'zh-CN') ? "启用" : 'enabled' },
                { value: 0, label: (window.sessionStorage.getItem('lang') == 'zh-CN') ? "禁用" : 'disabled' }
            ], // 状态字典
            systemTypeDic: [
                { value: 0, label: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '权限' : 'jurisdiction' },
                { value: 1, label: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '实物' : 'entity' }
            ], // 系统类型字典
            empstatusDic: [
                { value: 1, label: (window.sessionStorage.getItem('lang') == 'zh-CN') ? "在职" : 'Incumbent' },
                { value: 2, label: (window.sessionStorage.getItem('lang') == 'zh-CN') ? "离职" : 'resigned' }
            ],
            selectSection: [{ value: 0, label: this.$t('common.not') }, { value: 1, label: this.$t('common.is') }],
            selectSection1: [{ value: 1, label: this.$t('common.domainAccount') }, { value: 0, label: this.$t('common.nonDomainAccount') }],
            selectSectionActive: [{ value: 0, label: this.$t('common.nonActive') }, { value: 1, label: this.$t('common.active') }],
            pagination: {
                totalSize: 0,
                pageSize: 10,
                pageNum: 1,
                totalPage: 0
            },
            dataList: [],
            loadind: false,
            multipleSelection: [],
            chooseSelectionArr: [],
            newlyFormVisible: false,
            headArr: [
                { prop: "username", label: this.$t('common.byUserName'), index: 0 },
                { prop: "accountStatus", label: this.$t('common.accountStatus'), index: 1 },
                { prop: "empCode", label: this.$t('common.empCode'), index: 2 },
                { prop: "empName", label: this.$t('common.empName1'), index: 3 },
                { prop: "positionName", label: this.$t('common.positionName'), index: 4 },
                { prop: "orgName", label: this.$t('common.orgName'), index: 5 },
                { prop: "netCode", label: this.$t('common.netCode'), index: 6 },
                { prop: "empStatus", label: this.$t('common.empStatus'), index: 7 },
                { prop: "ownerSysName", label: this.$t('common.ownerSysName'), index: 8 },
                { prop: "resourceName", label: this.$t('common.ownerResourceName'), index: 9 },
                { prop: "dataGroupName", label: this.$t('common.dataGroupName'), index: 10 },
                { prop: "isCustom", label: this.$t('common.isCustom'), index: 11 },
                { prop: "dataGroupStatus", label: this.$t('common.dataGroupStatus'), index: 12 },
                { prop: "ruleType", label: this.$t('common.ruleType'), index: 13 },
                { prop: "startTm", label: this.$t('common.startTm'), index: 14 },
                { prop: "endTm", label: this.$t('common.endTm'), index: 15 },
                { prop: "accreditStatus", label: this.$t('common.accreditStatus'), index: 16 },
                { prop: "lastUpdator", label: this.$t('common.lastUpdator'), index: 17 },
                { prop: "lastUpdateTm", label: this.$t('common.lastUpdateTm'), index: 18 },
                { prop: "creator", label: this.$t('common.creator'), index: 19 },
                { prop: "createTm", label: this.$t('common.createTm'), index: 20 }
            ],
            tableVisibleArr: [],
            assignDataGroupVisible: false,
            handleDataAssignVisible: false,
            handleResourceBatchVisible: false,
            resourceOptions: []
        }
    },
    beforeCreate () {
    },
    mounted () {
        var pageObj = localStorage.getItem('basp_accountDataGroupManage') // 捞出缓存中的该页面的表格配置
        if (pageObj) {
            var obj = JSON.parse(pageObj)
            if (obj[sessionStorage.userName]) {
                this.saveAutoDefinedTable(obj[sessionStorage.userName])
            } else {
                this.tableVisibleArr = this.$deepCopy(this.headArr, [])
            }
        } else {
            this.tableVisibleArr = this.$deepCopy(this.headArr, [])
        }
        this.resourceOptionsFun('')
        this.searchHttp()
    },
    methods: {
        saveAutoDefinedTable (arr) { // 配置表格可见的选项
            var temp = []
            for (var i = 0; i < arr.length; i++) {
                temp.push(this.headArr[arr[i]])
            }
            this.tableVisibleArr = temp
        },
        async resourceOptionsFun (queryString) { // 资源名称模糊搜索
            this.resourceOptions = await this.$resourceOptionsFun(queryString)
        },
        selectableFun (row, index) {
            if (row.accreditStatus == 1) {
                return true
            } else {
                return false
            }
        },
        selectChange (val) { // 主列表change事件
            this.multipleSelection = val
        },
        searchHttp () {
            var param = {
                username: this.form.username,
                accountStatus: this.form.accountStatus,
                empCode: this.form.empCode,
                empName: this.form.empName,
                empStatus: this.form.empStatus,
                positionName: this.form.positionName,
                orgName: this.form.orgName,
                netCode: this.form.netCode,
                resourceCode: this.form.resourceName,
                dataGroupName: this.form.dataGroupName,
                dataGroupStatus: this.form.dataGroupStatus,
                ruleType: this.form.ruleType,
                accreditStatus: this.form.accreditStatus,
                startTm: this.form.startTm,
                endTm: this.form.endTm,
                pageSize: this.pagination.pageSize,
                pageNum: this.pagination.pageNum
            }
            this.loadind = true
            var that = this
            this.$httpExt().post('/dev-basp-user/accountDataGroup/queryList', param)
                .then((response) => {
                    this.loadind = false
                    var body = response.result
                    this.pagination.totalSize = body.totalSize
                    this.dataList = body.data
                    var tempSelectCurrent = []
                    if (that.chooseSelectionArr.length > 0) {
                        for (var i = 0; i < that.dataList.length; i++) {
                            for (var k = 0; k < that.chooseSelectionArr.length; k++) {
                                var resourceId1 = that.chooseSelectionArr[k].resourceId
                                var resourceId2 = that.dataList[i].resourceId
                                var byAccountId1 = that.chooseSelectionArr[k].byAccountId
                                var byAccountId2 = that.dataList[i].byAccountId
                                var dataGroupId1 = that.chooseSelectionArr[k].dataGroupId
                                var dataGroupId2 = that.dataList[i].dataGroupId
                                var sysAccountId1 = that.chooseSelectionArr[k].sysAccountId
                                var sysAccountId2 = that.dataList[i].sysAccountId
                                if (resourceId1 == resourceId2 && byAccountId1 == byAccountId2 && dataGroupId1 == dataGroupId2 && sysAccountId1 == sysAccountId2) {
                                    tempSelectCurrent.push(that.dataList[i])
                                    that.chooseSelectionArr.splice(k, 1)
                                    break
                                }
                            }
                        }
                    }
                    this.$nextTick(() => {
                        that.toggleSelection(tempSelectCurrent)
                    })
                }, (response) => {
                    this.loadind = false
                    Notification.error({
                        title: this.$t('common.exception'),
                        message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                    })
                })
        },
        toggleSelection (rows) {
            if (rows.length) {
			  rows.forEach(row => {
                    this.$refs["multipleTable"].toggleRowSelection(row)
			  })
            } else {
			  this.$refs["multipleTable"].clearSelection()
            }
        },
        handleCurrentChangePage (val) {
            this.chooseSelectionArr = this.chooseSelectionArr.concat(this.multipleSelection)
            this.pagination.pageNum = val
            this.searchHttp()
        },
        pageSizeChange (val) {
            this.chooseSelectionArr = this.chooseSelectionArr.concat(this.multipleSelection)
            this.pagination.pageNum = 1
            this.pagination.pageSize = val
            this.searchHttp()
        },
        resetSearch () {
            this.form = {
                username: '',
                accountStatus: '',
                empCode: '',
                empName: '',
                empStatus: '',
                positionName: '',
                orgName: '',
                netCode: '',
                resourceName: '',
                dataGroupName: '',
                dataGroupStatus: '',
                ruleType: '',
                isCustom: "",
                accreditStatus: 1,
                startTm: '',
                endTm: ''
            }// 重置搜索域
        },
        onSearch () {
            this.multipleSelection = []// 清空当前页面勾选项
            this.chooseSelectionArr = []// 清空页面所有勾选项
            this.pagination.pageNum = 1
            this.searchHttp()
        },
        empCodeSelect (item) {
            this.form.empCode = item.value
        },
        batchDisabledHttp (endTm) {
            var tempAllselectData = this.$deepCopy(this.chooseSelectionArr, [])
            tempAllselectData = tempAllselectData.concat(this.multipleSelection)
            var param = []
            for (var i = 0; i < tempAllselectData.length; i++) {
                param.push({
                    id: tempAllselectData[i].id,
                    resourceId: tempAllselectData[i].resourceId,
                    status: this.form.accreditStatus == 1 ? 0 : 1,
                    byAccountId: tempAllselectData[i].byAccountId,
                    dataGroupId: tempAllselectData[i].dataGroupId,
                    endTm: endTm
                })
            }
            this.$httpExt().post('/dev-basp-user/accountDataGroup/state', param)
                .then((response) => {
                    this.$message({
                        message: response.msg ? response.msg : (window.sessionStorage.getItem('lang') == 'zh-CN') ? '修改成功！' : 'Modified success!',
                        type: 'success'
                    })
                    this.onSearch()
                }, (response) => {
                    Notification.error({
                        title: this.$t('common.exception'),
                        message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                    })
                })
        },
        batchDisabled () {
            var tempAllselectData = this.$deepCopy(this.chooseSelectionArr, [])
            tempAllselectData = tempAllselectData.concat(this.multipleSelection)
            if (tempAllselectData.length > 0) {
                if (tempAllselectData[0].accreditStatus == 0) { // 禁用后不能启用
                    return
                }
                if (tempAllselectData[0].accreditStatus == 0) { // 启用操作
                    if (tempAllselectData[0].accountStatus === 0) {
                        this.$message({
                            message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '百源账号状态为禁用，不可启用' : "The status of baiyuan account  is disabled,so that it's not enabled!",
                            type: 'warning'
                        })
                    } else if (tempAllselectData[0].dataGroupStatus === 0) {
                        this.$message({
                            message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '当前数据组状态为禁用，不可启用' : "Current data group status is disabled ,so that it's not enabled!",
                            type: 'warning'
                        })
                    } else {
                        this.statusChange = true
                    }
                } else { // 禁用操作
                    this.$confirm(this.$t('modules.accountDataGroupManage.disableWornTip'), this.$t('common.tip'), {
					  	 confirmButtonText: this.$t('common.submitOption'),
                        cancelButtonText: this.$t('common.cancelOption')
                    }).then(() => {
                        this.batchDisabledHttp()
                    }).catch(() => {
                    })
                }
            } else {
                MessageBox({
                    message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '请至少选择一条数据进行操作!' : 'Please select at least one data for operation!',
                    confirmButtonText: this.$t('common.iknow')
                })
            }
        },
        stateChangeConfirm (dialogForm) { // 启用填完有效期确认
            this.statusChange = false
            this.batchDisabledHttp(dialogForm.endTm)
        },
        validityDateClose1 () {
            this.statusChange = false
        },
        validityDateClose () { // 关闭有效期修改模态框
            this.newlyFormVisible = false
        },
        // 提交修改的生效失效时间
        submitDateForm (dialogForm) {
            var urlH = '/dev-basp-user/accountDataGroup/update'
            var param = {
                byAccountId: this.dataSourceRow.byAccountId,
                dataGroupId: this.dataSourceRow.dataGroupId,
                id: this.dataSourceRow.id,
                resourceId: this.dataSourceRow.resourceId,
                startTm: dialogForm.startTm,
                endTm: dialogForm.endTm
            }
            let loadingInstance = Loading.service({ fullscreen: true })
            this.$httpExt().post(urlH, param)
                .then((response) => {
                    this.$message({
                        message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '修改角色授权时间成功！' : 'The role authorization time has been modified successfully!',
                        type: 'success'
                    })
                    this.newlyFormVisible = false
                    this.onSearch()
                    loadingInstance.close()
                }, (response) => {
                    loadingInstance.close()
                    Notification.error({
                        title: this.$t('common.exception'),
                        message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                    })
                })
        },
        // 判断勾选
        beforeupdate (param) {
            if (this.multipleSelection.length > 1) {
                MessageBox({
                    message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '请至少选择一条数据进行操作!' : 'Please select at least one data for operation!',
                    confirmButtonText: this.$t('common.iknow')
                })
            } else if (this.multipleSelection.length == 1) {
                if (this.multipleSelection[0].accreditStatus === 0) { // 修改
                    this.$message({
                        message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '当前记录授权状态为禁用，不可修改' : "The authorization status of current record  is disabled so that it's cannot be modified!",
                        type: 'warning'
                    })
                } else if (this.multipleSelection[0].accountStatus === 0) {
                    this.$message({
                        message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '当前百源账号状态为禁用，不可修改' : "The status of current baiyuan account is disabled so that it's cannot be modified!",
                        type: 'warning'
                    })
                } else if (this.multipleSelection[0].dataGroupStatus === 0) {
                    this.$message({
                        message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '当前数据组状态为禁用，不可修改' : "The status of current data group is disabled so that it's cannot be modified!",
                        type: 'warning'
                    })
                } else {
                    this.dataSourceRow = this.$deepCopy(this.multipleSelection[0])
                    if (this.multipleSelection[0].endTm <= this.$format(new Date().getTime(), "yyyy-MM-dd")) { // 已失效
                        this.$message({
                            message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '当前记录授权关系已失效，不可修改' : "The authorization relationship of current record  is invalid so that it's cannot be modified!",
                            type: 'warning'
                        })
                    } else {
                        this.update(this.multipleSelection[0])
                    }
                }
            } else {
                MessageBox({
                    message: (window.sessionStorage.getItem('lang') == 'zh-CN') ? '请至少选择一条记录进行操作!' : 'Please select at least one record for operation!',
                    confirmButtonText: this.$t('common.iknow')
                })
            }
        },
        update (row) { // 修改
            this.dataSourceRow = this.$deepCopy(row)
            this.newlyFormVisible = true
        },
        // 数据组预授权
        giveupFun (val) {
            this.$confirm(this.$t('modules.accountDataGroupManage.giveUpEditWornTip'), this.$t('common.tip'), {
			  	confirmButtonText: this.$t('common.submitOption'),
                cancelButtonText: this.$t('common.cancelOption')
            }).then(() => {
                this[val] = false
            }).catch(() => {
            })
        },
        dataHandleSave (form, arr) {
            var urlH = '/dev-basp-user/accountDataGroup/save'
            var param = []
            for (var i = 0; i < arr.length; i++) {
                param.push({
                    resourceId: arr[i].resourceId,
                    dataGroupId: arr[i].dataGroupId,
                    byAccountId: form.byAccountId,
                    startTm: form.startTm,
                    endTm: form.endTm
                })
            }
            let loadingInstance = Loading.service({ fullscreen: true })
            this.$httpExt().post(urlH, param)
                .then((response) => {
                    loadingInstance.close()
                    this.$message({
					  message: response.msg ? response.msg : this.$t('modules.accountDataGroupManage.datagroupAssignSuccess'),
					  type: 'success'
                    })
                    this.handleDataAssignVisible = false
                    this.multipleSelection = []// 清空当前页面勾选项
                    this.pagination.pageNum = 1
                    this.onSearch()
                }, (response) => {
                    loadingInstance.close()
                    Notification.error({
                        title: this.$t('common.exception'),
                        message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                    })
                })
        },
        dataHandleBatchSave (form, arr) {
            var urlH = '/dev-basp-user/accountDataGroup/save'
            var param = []
            for (var i = 0; i < arr.length; i++) {
                param.push({
                    resourceId: form.resourceId,
                    dataGroupId: form.dataGroupName,
                    byAccountId: arr[i].byAccountId,
                    startTm: form.startTm,
                    endTm: form.endTm
                })
            }
            if (form.dataGroupType == '2') {
                param = []
                for (var k = 0; k < form.dataGroupIdList.length; k++) {
                    param.push({
                        resourceId: form.resourceId,
                        dataGroupId: form.dataGroupIdList[k].dataGroupId,
                        byAccountId: form.dataGroupIdList[k].ownerAccount,
                        startTm: form.startTm,
                        endTm: form.endTm
                    })
                }
            }
            let loadingInstance = Loading.service({ fullscreen: true })
            this.$httpExt().post(urlH, param)
                .then((response) => {
                    loadingInstance.close()
                    this.$message({
					 message: response.msg ? response.msg : this.$t('modules.accountDataGroupManage.datagroupAssignSuccess'),
					  type: 'success'
                    })
                    this.handleResourceBatchVisible = false
                    this.multipleSelection = []// 清空当前页面勾选项
                    this.pagination.pageNum = 1
                    this.onSearch()
                }, (response) => {
                    loadingInstance.close()
                    Notification.error({
                        title: this.$t('common.exception'),
                        message: response.msg ? response.msg : this.$t('common.exceptionWornText')
                    })
                })
        },
		 getSearchAreaName (val) {
		   	switch (val) {
            case "resourceName":
                for (var b = 0; b < this.resourceOptions.length; b++) {
                    if (this.form.resourceName === this.resourceOptions[b].code) {
                        return this.resourceOptions[b].label
                    }
                }
                return this.$t('common.all')
            case "dataGroupStatus":
                for (var c = 0; c < this.statusDic.length; c++) {
                    if (this.form.dataGroupStatus === this.statusDic[c].value) {
                        return this.statusDic[c].label
                    }
                }
                return this.$t('common.all')
            case "empStatus":
                for (var e = 0; e < this.empstatusDic.length; e++) {
                    if (this.form.empStatus === this.empstatusDic[e].value) {
                        return this.empstatusDic[e].label
                    }
                }
                return this.$t('common.all')
            case "accountStatus":
                for (var f = 0; f < this.statusDic.length; f++) {
                    if (this.form.accountStatus === this.statusDic[f].value) {
                        return this.statusDic[f].label
                    }
                }
                return this.$t('common.all')
            case "ruleType":
                for (var g = 0; g < this.typeDic.length; g++) {
                    if (this.form.ruleType === this.typeDic[g].value) {
                        return this.typeDic[g].label
                    }
                }
                return this.$t('common.all')
            case "accreditStatus":
                for (var h = 0; h < this.statusDic.length; h++) {
                    if (this.form.accreditStatus === this.statusDic[h].value) {
                        return this.statusDic[h].label
                    }
                }
                return this.$t('common.all')
            default : return this.form[val]; 
		   	}
	  	},
        formatter (row, column) { // 状态信息中表格展开项的code转为name
            switch (column.property) {
            case "accountStatus":// 账号状态
                for (var i = 0; i < this.statusDic.length; i++) {
                    if (row.accountStatus == this.statusDic[i].value) {
                        return this.statusDic[i].label
                    }
                }
                return row.accountStatus
            case "empStatus":// 是否在职
                for (var a = 0; a < this.empstatusDic.length; a++) {
                    if (row.empStatus == this.empstatusDic[a].value) {
                        return this.empstatusDic[a].label
                    }
                }
                return row.empStatus
            case "dataGroupStatus":// 数据组状态
                for (var b = 0; b < this.statusDic.length; b++) {
                    if (row.dataGroupStatus == this.statusDic[b].value) {
                        return this.statusDic[b].label
                    }
                }
                return row.dataGroupStatus
            case "ruleType":// 规则类型
                for (var c = 0; c < this.typeDic.length; c++) {
                    if (row.ruleType == this.typeDic[c].value) {
                        return this.typeDic[c].label
                    }
                }
                return row.ruleType
            case "accreditStatus":// 授权状态
                for (var d = 0; d < this.statusDic.length; d++) {
                    if (row.accreditStatus == this.statusDic[d].value) {
                        return this.statusDic[d].label
                    }
                }
                return row.accreditStatus
            case "isCustom":// 是否自定义数据组
                for (var e = 0; e < this.selectSection.length; e++) {
                    if (row.isCustom == this.selectSection[e].value) {
                        return this.selectSection[e].label
                    }
                }
                return row.isCustom
            case "startTm":return this.$format(row.startTm, "yyyy/MM/dd hh:mm:ss");  // 开始时间
            case "endTm":return this.$format(row.endTm, "yyyy/MM/dd hh:mm:ss");  // 开始时间
            case "lastUpdateTm":return this.$format(row.lastUpdateTm, "yyyy/MM/dd hh:mm:ss");  // 开始时间
            case "createTm": return this.$format(row.createTm, "yyyy/MM/dd hh:mm:ss");  // 开始时间
            default : return row[column.property]; 
            }
        }
    }
}
</script>
<style lang="less">
@import "../common/css/common.less";
.dataBandResource{
	.el-collapse-item__header{
		font-weight: bold;
	}
	.searchTitle.el-form-item__label{
		width:110px;
	}
}
</style>
